package com.cloudptt.wp.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;

public class MainTitleLayout extends LinearLayout implements View.OnClickListener {

	private TextView titleTv;
	private TextView selfTv;
	private IMainTitleBtnAction action = null;

	public MainTitleLayout(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}

	public MainTitleLayout(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}

	public MainTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
		this(context, attrs, defStyleAttr, 0);
		// TODO Auto-generated constructor stub
	}

	public MainTitleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		// TODO Auto-generated constructor stub
		LayoutInflater.from(context).inflate(R.layout.layout_main_title, this);
		titleTv = (TextView)findViewById(R.id.titleTv);
		selfTv = (TextView)findViewById(R.id.selfTv);
		ImageView settingsBtn = (ImageView)findViewById(R.id.settingsBtn);
		settingsBtn.setOnClickListener(this);
		ImageView queryBtn = (ImageView)findViewById(R.id.queryBtn);
		queryBtn.setOnClickListener(this);
		ImageView addBtn = (ImageView)findViewById(R.id.addBtn);
		addBtn.setOnClickListener(this);
	}
	

	public void setTitle(int resid){
		Log.debug(MainTitleLayout.class, "setTitle resid = " + resid);
		if(titleTv != null){
			titleTv.setText(resid);
		}
	}
	public void setSelfName(String name){
		Log.debug(MainTitleLayout.class, "setSelfName name = " + name);
		if(selfTv != null)
		{
			selfTv.setText(name);
		}
	}
	public void setAction(IMainTitleBtnAction action) {
		this.action = action;
	}

	@Override
	public void onClick(View view) {
		if(action != null)
		{
			action.onBtnAction(view.getId());
		}
	}
}
